#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<assert.h>
#include<sys/types.h>
#include<sys/wait.h>
int main()
{
    printf("process is running...\n");
    pid_t id = fork();
    assert(id != -1);

    if(id == 0)
    {
        //这里的替换不会影响父进程，因为进程具有独立性
        sleep(1);
        //execl("/usr/bin/ls","ls","-a","-l","--color=auto",NULL);
        //
        //execlp("ls","ls","-a","-l","--color=auto",NULL);
        
        //char*const argv[] = {"ls", "-a", "-l", "--color=auto", NULL};
        //execv("/usr/bin/ls", argv);
        //execvp("ls", argv);
        char*const envp_[] = {(char*)"MYENV=111112223", NULL};
        extern char**environ;
        //execle("./mybin", "mybin", NULL, envp_);//自定义环境变量
        putenv((char*)"MYENV=1122345");//将指定环境变量导入到系统统环境变量中
        execle("./mybin", "mybin", NULL, environ);//系统环境变量
        exit(1);
    }
    int status = 0;
    pid_t ret = waitpid(id, &status, 0);
    if(ret > 0)
    {
        printf("wait success:exit code:%d, sig number:%d\n", (status >> 8) & 0xff, status & 0x7f);
    }








   // //.c-> load -> process -> 运行 -> 执行我们现在写的代码
   // printf("process is running...\n");
   // execl("/usr/bin/ls","ls","--color=auto","-a","-l",NULL);
   // //为什么这里的printf没有再执行了？printf也是代码，是在execl之后的。
   // //execl执行完毕之后，代码已经全部被覆盖了，开始执行新的程序的代码了，所以printf就无法执行了。i
   // printf("process is running done...\n");
   // return 0;
}
